< previous page page_601 next page >

Page 601
INSERT INTO_FROM statement is really just a SELECT_FROM query with an INSERT INTO TargetTable in front of it.
Now, let's update the SQLVB05.SQV to provide an example of the INSERT INTO_FROM statement. First, use SQL-VB5 to load and edit the SQLVB05.SQV script. Make changes to the script so that it matches Listing 15.3. Save the script and run it. Check your results against those shown in Figure 15.3.
Type.gifListing 15.3. Using the INSERT INTO_FROM statement.
//
// sqlvb05.sqv - Testing the INSERT INTO keyword
//
// create a new database
dbMake sqlvb05.mdb;
// create a new table
CREATE TABLE JobTitles
   (JobCounter COUNTER,
    JobID TEXT(5) CONSTRAINT PKJobTitle PRIMARY KEY,
    JobName TEXT(20),
    JobPay CURRENCY,
    JobDesc MEMO
   );
// insert some data
INSERT INTO JobTitles (JobID, JobName, JobDesc, JobPay) VALUES
   ('J001',
    'President',
    'Presides over the company',
    '50000'
   );
INSERT INTO JobTitles (JobID, JobName, JobDesc, JobPay) VALUES
   ('J002',
    'Vice President',
    'Does what the President tells him to do',
    '40000'
   );
INSERT INTO JobTitles (JobID, JobPay, JobName) VALUES
   ('J003',
    '35000',
    'Chief Engineer'
   );
// create a second table to hold some of the info from JobTitles
CREATE TABLE JobReport
   (JobID TEXT(5) CONSTRAINT PKJobReport PRIMARY KEY,
    JobName TEXT(20),
    JobDesc MEMO,
     DeptID  TEXT(5)
   );
// now append records from JobTitles into JobReport
INSERT INTO JobReport
   SELECT JobID, JobName, JobDesc FROM JobTitles;
continues

 
< previous page page_601 next page >

If you like this book, buy it!